//
//  JourneryNetHandler.m
//  Travel_M_Travel
//
//  Created by APPLE10 on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "JourneryNetHandler.h"
#import "AFNetworking.h"

@implementation JourneryNetHandler
+ (void)getDataWithUrl:(NSString *)str completion:(void (^)(NSData *))block
{
   
//    AFNetworkReachabilityManager *ma = [AFNetworkReachabilityManager ma ]
    
   NSString *URLTmp = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLTmp]];
    
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];

    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSString *requestTmp = [NSString stringWithString:operation.responseString];
        
        NSData *data = [[NSData alloc]initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];
 
        block (data);
//        NSLog(@"!!!!!resultDic = %@",[resultDic objectForKey:@"elements"]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"Faukure : %@", error);
    }];
    
    [operation start];
}
@end
